<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!--      <el-form-item label="用户id" prop="userId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.userId"-->
      <!--          placeholder="请输入用户id"-->
      <!--          clearable-->
      <!--          @keyup.enter="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="用户原图" prop="targetPicture">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.targetPicture"-->
      <!--          placeholder="请输入用户原图"-->
      <!--          clearable-->
      <!--          @keyup.enter="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="销售id" prop="saleUserId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.saleUserId"-->
      <!--          placeholder="请输入销售id"-->
      <!--          clearable-->
      <!--          @keyup.enter="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入客户昵称"
          clearable
          @keyup.enter="handleQuery"
          style="width: 150px"
        />
      </el-form-item>
      <el-form-item label="手机" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入手机"
          clearable
          @keyup.enter="handleQuery"
          style="width: 150px"
        />
      </el-form-item>
      <el-form-item label="顾问昵称" prop="saleName">
        <el-input
          v-model="queryParams.saleName"
          placeholder="请填写顾问昵称"
          clearable
          @keyup.enter="handleQuery"
          style="width: 150px"
        />
      </el-form-item>
      <el-form-item
        label="是否有填写补发诉求"
        prop="whetherDemands"
        label-width="150"
      >
        <el-input
          v-model="queryParams.whetherDemands"
          placeholder="请填写有或无"
          clearable
          @keyup.enter="handleQuery"
          style="width: 164px"
        />
      </el-form-item>
      <el-form-item label="来源" prop="sourceType" label-width="110">
        <el-select clearable v-model="queryParams.sourceType" placeholder="请选择"   @change="handleQuery">
          <el-option
            v-for="dict in sys_ai_source_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['business:aiChangeRecord:add']"
          >新增
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:aiChangeRecord:edit']"
          >修改
        </el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:aiChangeRecord:remove']"
          >删除
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['business:aiChangeRecord:export']"
          >导出
        </el-button>
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="aiChangeRecordList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="" align="center" prop="id" v-if="true"/>-->
      <el-table-column label="客户昵称" align="center" prop="nickName" />
      <el-table-column label="来源" align="center" prop="sourceType">
        <template #default="scope">
<!--          <dict-tag :options="sys_ai_source_type" :value="scope.row.sourceType"/>-->
          <el-tag effect="dark"  v-if="scope.row.sourceType == 1">官方小程序</el-tag>
          <el-tag effect="dark" type="success" v-else>抖音推广</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="注册时间" align="center" prop="registerTime" />
      <el-table-column label="最后一次换发时间" align="center" prop="lastTime" />
      <el-table-column label="手机号" align="center" prop="phonenumber" />
      <el-table-column
        label="服务顾问"
        align="center"
        prop="saleName"
      ></el-table-column>
      <el-table-column label="调用次数" align="center" prop="callNum" />
      <el-table-column label="补发诉求" align="center" prop="whetherDemands" />
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="450"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button link type="primary" @click="callInfo(scope.row)">最近三次调用详情</el-button>
<!--          <el-button link type="primary" @click="getUserExchangeRecord(scope.row.userId)">查询全部调用记录</el-button>-->
          <!-- <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:aiChangeRecord:edit']"
            >修改
          </el-button> -->
          <el-button
            link
            type="primary"
            @click="handleLookEdit(scope.row)"
            v-hasPermi="['business:aiChangeRecord:LookEdit']"
            >补发诉求表单
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

<!--    查询用户全部调用记录-->
    <el-dialog title="全部换发记录"   v-model="dialogTableVisible" width="1000px" append-to-body>
      <el-table :data="userExchangeRecord" max-height="500">
        <el-table-column property="targetPicture" label="用户原图">
          <template #default="scope">
            <ImagePreview
              :width="100" :height="100"
              :src="scope.row.targetPicture"
              :preview-src-list="[scope.row.targetPicture]"/>
          </template>
        </el-table-column>
        <el-table-column property="faceShape" label="脸型" />
        <el-table-column property="aiChangeRecordSub" label="选择发型数量">
          <template #default="scope">
            {{scope.row.aiChangeRecordSub.length}}
          </template>
        </el-table-column>
        <el-table-column property="sourceType" label="来源" />
        <el-table-column property="createTime" label="换发时间" />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-button link type="primary" @click="lookDrawer(scope.row)">查询换发对比</el-button>
          </template>
        </el-table-column>
      </el-table>
<!--      <ImageContrast>-->
<!--        <template #left>-->
<!--          <el-image-->
<!--            src="https://geekhair.oss-cn-beijing.aliyuncs.com/2024/03/12/42babb678b0f48d295409e4dd534c508.jpg"-->
<!--            fit="contain"-->
<!--          />-->
<!--        </template>-->
<!--        <template #right>-->
<!--          <el-image-->
<!--            src="https://geekhair.oss-cn-beijing.aliyuncs.com/2024/03/12/deb1756d62e7476e9996e15768a10535.jpg"-->
<!--            fit="contain"-->
<!--          />-->
<!--        </template>-->
<!--      </ImageContrast>-->
    </el-dialog>

    <el-drawer v-model="drawerOpen" direction="rtl" size="50%">
      <template #header>
        <h4>换发对比</h4>
      </template>
      <template #default>

        <el-row :gutter="530" v-for="item in userExchangeData">
          <el-col :span="6">
            <el-image
              :src="item.swapPicture"
              style="width: 500px;height: 600px"
              fit="cover"
            />
          </el-col>

          <el-col :span="6">
            <ImageContrast>
              <template #left>
                <el-image
                  :src="item.targetPicture"
                  fit="scale-down"
                />
              </template>
              <template #right>
                <el-image
                  :src="item.successPicture"
                  fit="scale-down"
                />
              </template>
            </ImageContrast>

          </el-col>
        </el-row>
      </template>
      <template #footer>
        <div style="flex: auto">
          <el-button @click="cancelClick">cancel</el-button>
          <el-button type="primary" @click="confirmClick">confirm</el-button>
        </div>
      </template>
    </el-drawer>

    <!-- 添加或修改用户换发记录对话框 -->
    <el-dialog
      :title="title"
      v-model="openAdd"
      append-to-body
      style="width: fit-content"
    >
      <el-form
        ref="aiChangeRecordRef"
        :model="form"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item label="用户手机号" prop="phoneNumber">
          <el-input
            v-model="form.phoneNumber"
            placeholder="请填写用户手机号"
            clearable
            style="width: 150px"
            type="tel"
            maxlength="11"
            @input="changePhone"
          />
          <el-tag
            type="danger"
            v-if="!isUserByPhoneStatus"
            style="margin-left: 20px"
            >当前用户不存在</el-tag
          >
        </el-form-item>

        <el-form-item label="用户原图" prop="targetPicture">
          <image-uploads
            v-model="form.targetPicture"
            :limit="1"
          ></image-uploads>
          <div class="tips" v-if="!form.targetPicture">
            ！请上传正脸照片全脸且露额头
          </div>
        </el-form-item>

        <el-form-item label="发型库" prop="targetPicture">
          <div class="">
            <div class="ai-img">
              <div class="scroll-content">
                <div
                  class="item-list"
                  v-for="item in aiHairstyleTypeList"
                  :key="item.id"
                  @click="onChooseHair(item)"
                  style="width: 100px; height: 100px"
                >
                  <el-image
                    :class="['image', item.picStatus ? 'active-imag' : '']"
                    :src="item.hairStockPhoto"
                    fit="cover"
                  />

                  <el-image class="right" :src="right" v-if="item.picStatus" />
                  <div class="flex-center hair-name" style="font-size: 14px">
                    {{ item.hairName }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm"
            >确 定</el-button
          >
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 查看调用详情 -->
    <el-dialog
      :title="title"
      v-model="openDetials"
      width="800px"
      append-to-body
      @close="closeRequestDialog"
    >
      <el-tabs v-model="activeName">
<!--        <el-tab-pane label="用户管理" name="first">用户管理</el-tab-pane>-->
<!--        <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>-->
<!--        <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>-->
<!--        <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>-->
        <el-tab-pane v-for="(item, id) in callList" :label="'调用' + ++id" :name="'调用' + id">
          <div class="call-info">
            <div class="call-info-1">时间:</div>
            <div class="call-info-2">{{ item.createTime }}</div>
          </div>

          <div class="call-info">
            <div class="call-info-1">原照片:</div>
            <div class="call-info-2">
              <image-preview
                :src="item.targetPicture"
                style="max-width: 200px; max-height: 200px"
              />
            </div>
          </div>

          <div class="call-info">
            <div class="call-info-1">风格选择:</div>
            <div class="call-info-2">
              <image-preview
                v-for="item in item.aiChangeRecordSub"
                :src="item.swapPicture"
                style="
                  max-width: 100px;
                  max-height: 100px;
                  margin-top: 20px;
                  margin-right: 20px;
                "
              />
            </div>
          </div>
          <div class="call-info">
            <div class="call-info-1">生成照片:</div>
            <div class="call-info-2">
              <image-preview
                v-for="item in item.aiChangeRecordSub"
                :src="item.successPicture"
                style="
                  max-width: 100px;
                  max-height: 100px;
                  margin-top: 20px;
                  margin-right: 20px;
                "
              />
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <!-- 补发诉求start -->
    <el-dialog :title="title" v-model="openDemand" width="800px" append-to-body>
      <div>请选择适合您的换发方案</div>
      <el-tabs>
        <el-tab-pane
          v-for="(item, index) in hairstyleDemandObj.geekAiChangeRecordVos"
          :label="`方案${Number(index) + 1}`"
        >
          <div class="ai-img" style="margin-bottom: 16px; height: 280px">
            <div class="scroll-content-1">
              <div
                class="item-list"
                v-for="(el, idx) in item.aiChangeRecordSub"
                :key="el.id"
                @click="onChooseHairStyle(el, item, index)"
              >
                <el-image
                  :class="['image', el.likeStatus === '1' ? 'active-imag' : '']"
                  :src="el.successPicture"
                  fit="cover"
                />

                <el-image
                  class="right"
                  :src="right"
                  v-if="el.likeStatus === '1'"
                />
                <div class="flex-center hair-name">{{ el.hairName }}</div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div>请选择适合您的补发选项</div>

      <!-- 风格选择： -->

      <div class="bottom-content content-2">
        <div
          class="ai-img"
          v-for="(item, index) in hairstyleDemandObj.demandsVoList"
          :key="item.key"
          style="margin-bottom: 16px; height: 160px"
        >
          <div class="title-1">{{ index + 1 }}.{{ item.key }}</div>
          <!-- <div class="scroll-content" :style="{ width: `${imgWidth + 80}px` }"> -->
          <div class="scroll-content-1">
            <div
              class="item-list el-list flex-column-center"
              v-for="(el, idx) in item.demands"
              :key="el.id"
              @click="
                onChooseHairOption(
                  hairstyleDemandObj.demandsVoList,
                  index,
                  el.id
                )
              "
              style="width: 100px; height: 100px"
            >
              <el-image
                :class="['image', el.selectStatus == 1 ? 'active-image' : '']"
                :src="el.optionImg"
                fit="cover"
              >
              </el-image>
              <el-image class="right" :src="right" v-if="el.selectStatus == 1">
              </el-image>
              <div class="option-name">{{ el.optionName }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 风格选择end -->

      <div class="bottom-btn" @click="onSubmit">
        <!-- <div :class="['submit', isSubmit ? 'active' : '']"> -->

        <el-button :loading="buttonLoading" :type="isSubmit ? 'primary' : ''"
          >提交</el-button
        >
        <!-- </div> -->
      </div>
    </el-dialog>

    <!-- 补发诉求end -->
  </div>
</template>

<script setup name="AiChangeRecord">
import {
  getExchangeRecord,
  listAiChangeRecord,
  getAiChangeList,
  getAiChangeRecord,
  delAiChangeRecord,
  onlineHairChangeApi,
  updateAiChangeRecord,
  checkUserByPhoneApi,
  queryHairstyleDemandApi,
  updateUserFavoriteHairstyleApi,
  updateUserDemandsApi,
} from "@/api/business/aiChangeRecord";

import { listAiHairstyleType } from "@/api/business/aiHairstyleType";
import right from "@/assets/images/right.png";
import { ElMessageBox } from 'element-plus'
const { proxy } = getCurrentInstance();
const { sys_ai_source_type} = proxy.useDict( "sys_ai_source_type");
const aiChangeRecordList = ref([]);
const aiHairstyleTypeList = ref([]); //发型库
const chooseImgList = ref([]); //选中的发型
const hairstyleDemandObj = ref({}); //补发诉求
const isNextStatus = ref(false);
const isUserByPhoneStatus = ref(true); //检测当前用户是否存在
const selectData = ref([]);
const pramasData = ref([]);
const userId = ref(undefined); //用户id
const activeName = ref("调用1");
const callList = ref([]);
const drawerOpen = ref(false); // 抽屉打开状态
const dialogTableVisible  = ref(false); // 打开调用详情
const openDetials = ref(false); // 打开调用详情
const openDemand = ref(false); //打开诉求
const openAdd = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const exchangeTotal = ref(0);
const title = ref("");
const isSubmit = ref(false); //是否可以提交
const chooseImgId = ref(undefined); //选中图片id;
const userExchangeRecord = ref([]);
const userExchangeData =  ref([]);
import useUserStore from "@/store/modules/user";
import {get} from "@vueuse/core";

const userStore = useUserStore();
console.log(userStore, "userStore");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userId: undefined,
    targetPicture: undefined,
    saleUserId: undefined,
  },
  rules: {
    // id: [{ required: true, message: "不能为空", trigger: "blur" }],
    phoneNumber: [
      { required: true, message: "用户手机号不能为空", trigger: "blur" },
    ],
    // userId: [{ required: true, message: "用户id不能为空", trigger: "blur" }],
    targetPicture: [
      { required: true, message: "用户原图不能为空", trigger: "blur" },
    ],
    // saleUserId: [
    //   { required: true, message: "销售id不能为空", trigger: "blur" },
    // ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询用户换发记录列表 */
function getList() {
  loading.value = true;
  listAiChangeRecord(queryParams.value).then((response) => {
    aiChangeRecordList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function lookDrawer(row){
  userExchangeData.value = row.aiChangeRecordSub
  drawerOpen.value = true
}

function cancelClick() {
  drawerOpen.value = false
}
function confirmClick() {
  ElMessageBox.confirm(`Are you confirm to chose ${radio1.value} ?`)
    .then(() => {
      drawerOpen.value = false
    })
    .catch(() => {
      // catch error
    })
}

function getUserExchangeRecord(userId){
  getExchangeRecord(userId,{pageNum: 1, pageSize: 999}).then((response) => {
    userExchangeRecord.value = response.rows;
    // exchangeTotal.value = response.total;
    dialogTableVisible.value = true
  });
}

/** 查询极客侠小程序ai发型库列表 */
function getHairList() {
  loading.value = true;
  let data = {
    pageNum: 1,
    pageSize: 99999,
    status: 0
  };
  listAiHairstyleType(data).then((response) => {
    console.log(response);
    response.rows.forEach((item) => {
      item.picStatus = false;
    });
    aiHairstyleTypeList.value = response.rows;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  openAdd.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    userId: null,
    sourceType: null,
    targetPicture: null,
    saleUserId: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    delFlag: null,
  };
  proxy.resetForm("aiChangeRecordRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  openAdd.value = true;
  title.value = "代换发";
}

/**
 * 查询调用详情
 */
function callInfo(row) {
  getAiChangeList(row.userId).then((res) => {
    callList.value = res.data;
    openDetials.value = true;
    title.value = "调用详情";
  });
}

// 监听手机号输入
function changePhone(e) {
  if (e.length === 11) {
    checkUserByPhoneApi(e).then((res) => {
      if (res.data && res.data.userId) {
        console.log("yonghucuan");
        isUserByPhoneStatus.value = true;
        form.value.userId = res.data.userId;
      } else {
        console.log("88888888");
        isUserByPhoneStatus.value = false;
      }
    });
  }
}

function closeRequestDialog(){
  activeName.value = "调用1";
}

// 点击选择发型
const onChooseHair = (item) => {
  if (chooseImgList.value.length >= 9) {
    let arr = [];
    chooseImgList.value.filter((el) => {
      if (el.id === item.id) {
        item.picStatus = false;
      } else {
        return arr.push(el);
      }
    });
    chooseImgList.value = arr;
    if (arr.length >= 9) {
      proxy.$modal.msgError("最多选择9款发型");
    }
    return;
  }
  isNextStatus.value = false;
  item.picStatus = !item.picStatus;
  chooseImgList.value = aiHairstyleTypeList.value.filter((el) => el.picStatus);
};

/** 修改按钮操作 */
function handleUpdate(row) {
  loading.value = true;
  reset();
  const _id = row.id || ids.value;
  getAiChangeRecord(_id).then((response) => {
    loading.value = false;
    form.value = response.data;
    open.value = true;
    title.value = "修改用户换发记录";
  });
}

/** 提交按钮 */
function submitForm() {
  if (!isUserByPhoneStatus.value) {
    proxy.$modal.msgError("当前用户不存在");
    return;
  }
  if (chooseImgList.value.length < 3) {
    proxy.$modal.msgError("最少选择三款发型");
    return;
  }
  proxy.$refs["aiChangeRecordRef"].validate((valid) => {
    if (valid) {
      buttonLoading.value = true;
      loading.value = true;
      if (form.value.id != null) {
        updateAiChangeRecord(form.value)
          .then((response) => {
            proxy.$modal.msgSuccess("修改成功");
            openAdd.value = false;
            getList();
          })
          .finally(() => {
            buttonLoading.value = false;
          });
      } else {
        let data = {
          ...form.value,
          hairstyleTypes: chooseImgList.value,
        };
        console.log(data);
        // return;
        onlineHairChangeApi(data)
          .then((response) => {
            if (response.code == 200) {
              loading.value = false;
              proxy.$modal.msgSuccess("新增成功");
              openAdd.value = false;
              getList();
            } else {
              buttonLoading.value = false;
              openAdd.value = false;
              proxy.$modal.msgError("新增失败");
            }
          })
          .finally(() => {
            buttonLoading.value = false;
            openAdd.value = false;
          });
      }
    }
  });
}

/**
 * 修改查看补发诉求
 */

function handleLookEdit(row) {
  loading.value = true;
  const _id = row.userId || ids.value;
  userId.value = _id;
  queryHairstyleDemandApi(_id).then((response) => {
    response.data.geekAiChangeRecordVos.forEach((o) => {
      o.aiChangeRecordSub.forEach((val) => {
        chooseImgId.value = val.id;
      });
    });
    response.data.demandsVoList.forEach((val) => {
      val.demands.forEach((el) => {
        pramasData.value.push(el);
        if (el.selectStatus == 1) {
          selectData.value.push(el);
        }
      });
    });

    hairstyleDemandObj.value = response.data;
    console.log(response, "查询我的补发诉求");
    title.value = "修改查看补发诉求";
    loading.value = false;
    openDemand.value = true;
  });
}

// 点击选择方案
function onChooseHairStyle(el, item, index) {
  hairstyleDemandObj.value.geekAiChangeRecordVos.forEach((o) => {
    if (o.id === item.id) {
      o.aiChangeRecordSub.forEach((val) => {
        if (el.id === val.id) {
          val.likeStatus = "1";
          chooseImgId.value = val.id;
        } else {
          val.likeStatus = "0";
        }
      });
    } else {
      o.aiChangeRecordSub.forEach((a) => {
        a.likeStatus = "0";
      });
    }
  });
}

// 点击选择诉求的图片
function onChooseHairOption(item, index, id) {
  selectData.value = [];
  pramasData.value = [];
  item[index].demands.forEach((el) => {
    if (el.id === id) {
      el.selectStatus = 1;
    } else {
      el.selectStatus = 0;
    }
  });
  // item.selectStatus = 1;
  // optionImgId.value = item.id;

  hairstyleDemandObj.value.demandsVoList.forEach((val) => {
    val.demands.forEach((el) => {
      pramasData.value.push(el);
      if (el.selectStatus == 1) {
        selectData.value.push(el);
      }
    });
  });
  console.log(selectData.value);
}

// 提交补发诉求
async function onSubmit() {
  if (!isSubmit.value) return;
  buttonLoading.value = true;
  await updateUserFavoriteHairstyleApi({
    userId: userId.value,
    aiChangeRecordId: chooseImgId.value,
  });
  updateUserDemandsApi(pramasData.value)
    .then((res) => {
      if (res.code == 200) {
        buttonLoading.value = false;
        openDemand.value = false;
        proxy.$modal.msgSuccess("修改成功");
      } else {
        buttonLoading.value = false;
        openDemand.value = false;
        proxy.$modal.msgError("修改失败");
      }
    })
    .finally(() => {
      buttonLoading.value = false;
      openDemand.value = false;
    });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm('是否确认删除用户换发记录编号为"' + _ids + '"的数据项？')
    .then(function () {
      loading.value = true;
      return delAiChangeRecord(_ids);
    })
    .then(() => {
      loading.value = true;
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {})
    .finally(() => {
      loading.value = false;
    });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "business/aiChangeRecord/export",
    {
      ...queryParams.value,
    },
    `aiChangeRecord_${new Date().getTime()}.xlsx`
  );
}
getHairList(); //获取发型库
getList();

watch(
  () => [chooseImgId.value, selectData.value],
  (newValue, oldValue) => {
    console.log(newValue, oldValue);
    if (
      newValue[0] &&
      newValue[1].length === hairstyleDemandObj.value.demandsVoList.length
    ) {
      isSubmit.value = true;
    } else {
      isSubmit.value = false;
    }
  }
);
</script>
<style lang="scss" scoped>
.tips {
  margin-left: 20px;
  font-weight: 600;
  color: red;
}

.ai-img {
  // width: 750px;
  height: 400px;
  background: #ffffff;
  border-radius: 40px 40px 0px 0px;
  // margin-top: 50px;
  .title-1 {
    margin: 20px 0;
  }
  .scroll-content {
    display: grid;
    grid-template-columns: auto auto auto auto auto auto auto;
    // grid-template-columns: repeat(4, 25%);
    grid-row-gap: 64px;
    height: 400px;
    width: 750px;
    justify-content: space-between;
    overflow: auto;
    .item-list {
      position: relative;
      width: 160px;
      height: 224px;
      display: block;
      .image {
        width: 100%;
        height: 100%;
        border-radius: 12px;
      }
      .right {
        position: absolute;
        top: -6px;
        right: -4px;
        width: 38px;
        height: 38px;
        z-index: 5;
      }
      .hair-name {
        font-size: 24px;
        color: rgba(0, 0, 0, 0.9);
        text-align: center;
      }
      .option-name {
        text-align: center;
      }
    }
    .active-imag {
      border-radius: 12px;
      border: 2px solid #7a9629;
    }
  }

  .scroll-content-1 {
    display: flex;
    height: 280px;
    width: fit-content;
    .item-list {
      position: relative;
      width: 160px;
      height: 224px;
      display: block;
      margin-right: 20px;
      .image {
        width: 100%;
        height: 100%;
        border-radius: 12px;
      }
      .right {
        position: absolute;
        top: -6px;
        right: -4px;
        width: 38px;
        height: 38px;
        z-index: 5;
      }
      .hair-name {
        font-size: 24px;
        color: rgba(0, 0, 0, 0.9);
        text-align: center;
      }
      .option-name {
        text-align: center;
      }
    }
    .active-imag {
      border-radius: 12px;
      border: 2px solid #7a9629;
    }
  }
  .ai-save {
    width: 366px;
    height: 76px;
    background: #e4e4e4;
    border-radius: 38px;
    font-size: 32px;
    font-weight: 600;
    color: #aaaaaa;
    z-index: 9;
    margin-top: 20px;
  }
  .active {
    background: linear-gradient(180deg, #c8f946 0%, #76f82b 100%);
    color: rgba(0, 0, 0, 0.9);
  }
}
.call-info {
  display: flex;
  align-items: center;
  margin-top: 20px;
  .call-info-1 {
    width: 120px;
  }
}
.bottom-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
  position: relative;
}
.submit {
  width: 366px;
  height: 38px;
  background: #e4e4e4;
  border-radius: 38px;
  font-size: 16px;
  font-weight: 600;
  color: #aaaaaa;
  line-height: 38px;
  text-align: center;
}
.active {
  background: linear-gradient(180deg, #c8f946 0%, #76f82b 100%);
  color: #333333;
}
</style>
